﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EducationManagementSystem.WebSite
{
    public partial class login2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (TextBox2.Text == "" && TextBox1.Text == "")
            {
            }
            else
            {
                this.TextBox1.Attributes["value"] = TextBox1.Text;//给密码value属性
                if (RadioButton1.Checked)
                {
                    SqlConnection conn = DB.Conn();
                    conn.Open();
                    string sql = "select stuname from student where stuid='" + TextBox2.Text + "' and stupwd='" + TextBox1.Text + "'";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    object obj = cmd.ExecuteScalar();
                    if (obj != null)
                    {
                        Session["stuid"] = TextBox2.Text;
                        Session["sname"] = obj.ToString();
                        Response.Redirect("Student/Stuleft.aspx");
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert(' 没有匹配的信息，登录失败 '); </script> ");
                    }
                }
                else if (RadioButton2.Checked)
                {
                    SqlConnection conn = DB.Conn();
                    conn.Open();
                    string sql = "select zhurenname from zhuren where zhurenid='" + TextBox2.Text + "' and zhurenpwd='" + TextBox1.Text + "'";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    object obj = cmd.ExecuteScalar();
                    if (obj != null)
                    {
                        Session["zhurenid"] = TextBox2.Text;
                        Session["zname"] = obj.ToString();

                        Response.Redirect("Zr/ZRLeft.aspx");
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert(' 没有匹配的信息，登录失败 '); </script> ");
                    }
                }
                else if (RadioButton3.Checked)
                {
                    SqlConnection conn = DB.Conn();
                    conn.Open();
                    string sql = "select * from admin where adminname='" + TextBox2.Text + "' and adminpwd='" + TextBox1.Text + "'";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    object obj = cmd.ExecuteScalar();
                    if (obj != null)
                    {
                        Session["aname"] = TextBox2.Text;
                        Response.Redirect("Admin/AdminLeft.aspx");
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert(' 没有匹配的信息，登录失败 '); </script> ");
                    }
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script>alert('请选择相应身份的按钮'); </script> ");
                }
            }
        }


    }
}